package com.vonchange.purchase.dr.sys.service.impl;

import java.util.Collection;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.dorado.data.entity.EntityState;
import com.bstek.dorado.data.entity.EntityUtils;
import com.vonchange.purchase.dr.sys.service.IDRSysDictItemService;
import com.vonchange.purchase.dr.sys.service.IDRSysDictService;
import com.vonchange.purchase.sys.bean.SysDict;
import com.vonchange.purchase.sys.dao.ISysDictDao;
import com.vonchange.utils.crud.dao.IBaseDao;
import com.vonchange.utils.crud.service.dr.impl.DRServiceImpl;
@Service
@Transactional
public class DRSysDictServiceImpl extends DRServiceImpl<SysDict> implements IDRSysDictService{

	@Resource
	private ISysDictDao sysDictDao;
	@Resource
	private IDRSysDictItemService sysDictItemService;
	@Override
	public IBaseDao<SysDict> getDao() {
		return sysDictDao;
	}
	@Override
	public void saveCud(Collection<SysDict> datas) {
		for (SysDict bean : datas) {
    		if (EntityUtils.getState(bean).equals(EntityState.NEW)) {
    			bean.setCreateTime( new Date());
    			getDao().save(bean);
			}
			if (EntityUtils.getState(bean).equals(EntityState.DELETED)) {
				bean.setIsDelete(1);
				bean.setUpdateTime(new Date());
			    getDao().update(bean);
			}
			if (EntityUtils.getState(bean).equals(EntityState.MODIFIED)) {
				bean.setUpdateTime(new Date());
				getDao().update(bean);
			}
			if (null!=bean.getSysDictItems()) {
				sysDictItemService.saveCud(bean.getSysDictItems(),bean.getId());
			}
    	}
    }

}
